package com.lyloou.practice.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author 应癫
 */
public class Result implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean, DisposableBean {

    private String status;
    private String message;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Result{" +
                "status='" + status + '\'' +
                ", message='" + message + '\'' +
                '}';
    }

    @Override
    public void setBeanName(String s) {
        System.out.println(String.format("BeanNameAware.setBeanName(%s)", s));
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println(String.format("BeanFactoryAware.setBeanFactory(%s)", beanFactory));
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(String.format("ApplicationContextAware.setApplicationContext(%s)", applicationContext));
    }

    private void initMethod() {
        System.out.println("Result.initMethod");
    }

    private void destroyMethod() {
        System.out.println("Result.destroyMethod");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("Result.preDestroy");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("Result.postConstruct");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("Result.afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("Result.destroy");
    }
}
